//
//  NSMutableArray+Tool.m
//  JewelryStore
//
//  Created by apple on 2016/12/23.
//  Copyright © 2016年 com. All rights reserved.
//

#import "NSMutableArray+Tool.h"

@implementation NSMutableArray (Tool)

- (BOOL)isSlectedCell:(NSInteger)tag
{
    StatusModel *model = self[tag];
        
    return model.isSelected;
}

- (BOOL)isAllSlected
{
    for (StatusModel *model in self) {
        
        if (model.isSelected == NO)
        {
            return NO;
        }
    }
    
    if (self.count == 0)
    {
        return NO;
    }
    
    return YES;
}

- (NSMutableArray *)changeSelectStauts:(NSInteger)index
{
    StatusModel *model = self[index];
    
    model.isSelected = !model.isSelected;
    
    [self replaceObjectAtIndex:index withObject:model];
    
    return self;
}

- (NSMutableArray *)selectAllStatus
{
    [self enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        StatusModel *model = obj;
        
        model.isSelected = YES;
        
        [self replaceObjectAtIndex:idx withObject:model];
    }];
    return self;
}

- (NSMutableArray *)getSelectedArray
{
    NSMutableArray *array = [NSMutableArray array];
    
    for (StatusModel *model in self) {
        
        if (model.isSelected == YES) {
            
            [array addObject:model];
        }
    }
    return array;
}

- (CGFloat)calculateTotalPriceOfSelectedCell
{
    CGFloat reslut;
    
    for (StatusModel *model in self) {
        
        if (model.isSelected)
        {
            reslut += model.totalPrice;
        }
    }
    return reslut;
}

- (int)calculateTotalNumOfSelectedCell
{
    int result = 0;
    
    for (StatusModel *model in self)
    {
        if (model.isSelected)
        {
            result += model.number;
        }
    }
    return result;
}
@end
